package com.holiday.springboot2.intercepter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 *  1、作用：将拦截器某个类，配置到这个类中。则程序就会识别
 *  2、自定义类，并实现WebMvcConfigurer，重写方法 addInterceptors
 *      1、addInterceptors：这个方法即配置拦截器某个类，与需要拦截的路径
 *  3、添加@Configuration注解
 */
@Configuration
public class CustomWebMvcCOnfigurer implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截类
        registry.addInterceptor(getLoginIntercepter())
                // 配置拦截路径
                .addPathPatterns("/api/v1/pri/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }


    @Bean
    public LoginIntercepter getLoginIntercepter() {
        return new LoginIntercepter();
    }
}
